;
(function (funcName, baseObj) {
    // The public function name defaults to window.docReady
    // but you can pass in your own object and own function name and those will be used
    // if you want to put them in a different namespace
    funcName = funcName || "docReady";
    baseObj = baseObj || window;
    var readyList = [];
    var readyFired = false;
    var readyEventHandlersInstalled = false;

    // call this when the document is ready
    // this function protects itself against being called more than once
    function ready() {
        if (!readyFired) {
            // this must be set to true before we start calling callbacks
            readyFired = true;
            for (var i = 0; i < readyList.length; i++) {
                // if a callback here happens to add new ready handlers,
                // the docReady() function will see that it already fired
                // and will schedule the callback to run right after
                // this event loop finishes so all handlers will still execute
                // in order and no new ones will be added to the readyList
                // while we are processing the list
                readyList[i].fn.call(window, readyList[i].ctx);
            }
            // allow any closures held by these functions to free
            readyList = [];
        }
    }

    function readyStateChange() {
        if (document.readyState === "complete") {
            ready();
        }
    }

    // This is the one public interface
    // docReady(fn, context);
    // the context argument is optional - if present, it will be passed
    // as an argument to the callback
    baseObj[funcName] = function (callback, context) {
        if (typeof callback !== "function") {
            throw new TypeError("callback for docReady(fn) must be a function");
        }
        // if ready has already fired, then just schedule the callback
        // to fire asynchronously, but right away
        if (readyFired) {
            setTimeout(function () {
                callback(context);
            }, 1);
            return;
        } else {
            // add the function and context to the list
            readyList.push({
                fn: callback,
                ctx: context
            });
        }
        // if document already ready to go, schedule the ready function to run
        if (document.readyState === "complete") {
            setTimeout(ready, 1);
        } else if (!readyEventHandlersInstalled) {
            // otherwise if we don't have event handlers installed, install them
            if (document.addEventListener) {
                // first choice is DOMContentLoaded event
                document.addEventListener("DOMContentLoaded", ready, false);
                // backup is window load event
                window.addEventListener("load", ready, false);
            } else {
                // must be IE
                document.attachEvent("onreadystatechange", readyStateChange);
                window.attachEvent("onload", ready);
            }
            readyEventHandlersInstalled = true;
        }
    }
})("docReady", window);
(function () {
    function sendErr(news) {
        news = JSON.stringify(news);
        news = 'payload=' + news;
        var xhr = new XMLHttpRequest();
        xhr.responseType = "JSON";
        xhr.open('POST', 'https://hook.bearychat.com/=bwEne/incoming/50fe6592e6e0bc6396afaf5ebd52792e', true); // 上报给node中间层处理
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // 设置请求头
        xhr.send(news);
    };

    window.onerror = function (errorMessage, scriptURI, lineNo, columnNo, userAgent, error) {
        // 构建错误对象
        var errorObj = {
            errorMessage: errorMessage || null, // 异常信息
            scriptURI: scriptURI || null, // 异常文件路径
            lineNo: lineNo || null, // 异常行号
            columnNo: columnNo || null, // 异常列号
            stack: error && error.stack ? error.stack : null // 异常堆栈信息
        };
        // "** 异常信息: **"+errorObj.errorMessage+"。"+"异常行号-"+errorObj.lineNo+"。异常列号-"+errorObj.columnNo+"。异常堆栈信息："+errorObj.stack
        // http://test.xiaogj.com/js/libs/nanoscroller/jquery.nanoscroller.min.js.map
        console.log(errorObj);
        var lncomingPar = {
            "text": "错误提醒！", //标题
            "markdown": true,
            // "channel":"",//讨论组名字
            "user": "Chendye", //用户名
            "attachments": [{
                "title": window.navigator.userAgent,
                "text": "{** errorMessage : **" + errorObj.errorMessage + "," +
                    " ** scriptURI : **" + errorObj.scriptURI + "," +
                    " ** lineNo : **" + errorObj.lineNo + "," +
                    "** columnNo : **" + errorObj.columnNo + "," +
                    "** stack : **" + errorObj.stack +
                    "}",
                "color": "#ff111f",
            }]
        };
        sendErr(lncomingPar);
    };
    window.errorCatch=function(framework){
        console.log(framework)
        switch (framework) {
            case 'vue':
            Vue.config.errorHandler = function (err, vm, info) {
                let {
                    message,
                    name,
                    script,
                    line,
                    column,
                    stack
                } = err;
                let lncomingPar = {
                    "text": "vue异常报告！", //标题
                    "markdown": true,
                    // "channel":"",//讨论组名字
                    "user": "3033244122@qq.com", //用户名
                    "attachments": [{
                        "title": "异常类型:" + name,
                        "text": stack + " ** userAgent : **" + window.navigator.userAgent,
                        "color": "#ff111f",
                    }]
                };
                sendErr(lncomingPar);
            }
            break;
        
            default:
                break;
        }
    }
}());